/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Jun 25, 2012  11:42:21 AM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.construction.goods.returns
 * File Name : GpProcessing.java
 * TODO
 */
package apps.business.process.construction.goods.receipted;

import java.util.List;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import jpa.entitys.synchro.staging.MmGoodsreceiptOutb;
import sap.business.mm.outbound.SyncGoodsReceiptService;
import sun.reflect.generics.tree.Tree;
import apps.business.process.SyncProcessorCommons;
import apps.promis.out.construction.VwSyncGrnItemAction;

/**
 * @author chatree
 *
 */
public class GpProcessing extends SyncProcessorCommons {
	
	private static final Logger log = Logger.getLogger(GpProcessing.class);

	/**
	 * 
	 */
	public GpProcessing() {
		// TODO Auto-generated constructor stub
	}
	
	public void Processing(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception {
		try{
				
			UPD_PROMISUseTime(true, false, null);
			List<MmGoodsreceiptOutb> value_list = new VwSyncGrnItemAction().CreateToStaging(company, project, documentNo, status, syncIsstaging);
			UPD_PROMISUseTime(false, true, null);
			System.out.println(" Create to PROMIS. size=" + CommonService.getSize(value_list));
			
			if(CommonService.getSize(value_list) > 0){
				UPD_SENDUseTime(true, false, value_list.get(0).getInstanceNo());
				new SyncGoodsReceiptService().SendToSAP(value_list);
				UPD_SENDUseTime(false, true, value_list.get(0).getInstanceNo());
			}
			
			System.out.println(" Send to SAP. size=" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
